package com.example.admin.interceptor;

import com.example.admin.annotation.LoginInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method;

@Slf4j
public class AuthorityInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HandlerMethod handlerMethod = (HandlerMethod) handler;

        Method method = handlerMethod.getMethod();

        LoginInterceptor loginInterceptor = method.getAnnotation(LoginInterceptor.class);

        if (loginInterceptor != null) {
            log.info("执行登录操作");

            return true;
        }

        return true;
    }
}
